#ifndef _WX_GENERIC_GRIDSEL_H_
#define _WX_GENERIC_GRIDSEL_H_

#include "wx/defs.h"

#if wxUSE_GRID

#include "wx/grid.h"

class wxGridSelection {
  public:
    wxGridSelection( wxGrid * grid, wxGrid::wxGridSelectionModes sel =
                       wxGrid::wxGridSelectCells );
    bool IsSelection();
    bool IsInSelection( int row, int col );
    void SetSelectionMode( wxGrid::wxGridSelectionModes selmode );
    wxGrid::wxGridSelectionModes GetSelectionMode() { return m_selectionMode; }
    void SelectRow( int row,bool ControlDown = false,  bool ShiftDown = false,bool AltDown = false, bool MetaDown = false );
    void SelectCol( int col,bool ControlDown = false,  bool ShiftDown = false,
                    bool AltDown = false, bool MetaDown = false );
    void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, bool ControlDown = false,
                      bool ShiftDown = false, bool AltDown = false, bool MetaDown = false, bool sendEvent = true );
    void SelectCell( int row, int col, bool ControlDown = false,  bool ShiftDown = false,
                     bool AltDown = false, bool MetaDown = false, bool sendEvent = true );
    void ToggleCellSelection( int row, int col, bool ControlDown = false, bool ShiftDown = false,
                              bool AltDown = false, bool MetaDown = false );
    void ClearSelection();

    void UpdateRows( size_t pos, int numRows );
    void UpdateCols( size_t pos, int numCols );

  private:
    int BlockContain( int topRow1, int leftCol1, int bottomRow1, int rightCol1, int topRow2, int leftCol2,
                      int bottomRow2, int rightCol2 );
    int BlockContainsCell( int topRow, int leftCol, int bottomRow, int rightCol, int row, int col ) {
      return ( topRow <= row && row <= bottomRow &&
               leftCol <= col && col <= rightCol );
    }

    wxGridCellCoordsArray               m_cellSelection;
    wxGridCellCoordsArray               m_blockSelectionTopLeft;
    wxGridCellCoordsArray               m_blockSelectionBottomRight;
    wxArrayInt                          m_rowSelection;
    wxArrayInt                          m_colSelection;

    wxGrid                              *m_grid;
    wxGrid::wxGridSelectionModes        m_selectionMode;

    friend class wxGrid;

    DECLARE_NO_COPY_CLASS( wxGridSelection )
};

#endif
#endif
